package com.acwing.lc.part1;

import com.acwing.lc.common.ListNode;

/**
 * @author rkc
 * @date 2022/9/11 9:18
 */
public class LC24两两交换链表中的节点 {

    public ListNode swapPairs(ListNode head) {
        ListNode dummy = new ListNode(-1, head);
        ListNode p = dummy;
        while (p.next != null && p.next.next != null) {
            ListNode a = p.next, b = a.next;
            p.next = b;
            a.next = b.next;
            b.next = a;
            p = a;
        }
        return dummy.next;
    }
}
